package com.xywy.start;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

import com.xywy.R;
import com.xywy.common.BaseActivity;
import com.xywy.common.widget.TitleBar;
import com.xywy.start.widget.HeightView;

/**
 * 身高
 * 
 * @author xiaogd
 * 
 */
public class HeightActivity extends BaseActivity {
	private static final String TAG = "HeightActivity";

	private TextView heightShow;
	private Handler mHandler;
	HeightView heightView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 设置为全屏
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.start_height);

		this.initView();
		this.initHandler();
		this.loadData();
	}

	private void initHandler() {
		mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) { // 子线程返回的消息
				heightShow.setText(String.valueOf(msg.obj));
			}
		};
	}

	public void startOnClick(View view) {
		switch (view.getId()) {
		case R.id.bt_height_next:
			next();
			break;
		}
		;
	}

	private void next() {
		Intent intent = new Intent(this, SexActivity.class);
		int height = new Integer(heightShow.getText().toString());
//		Intent fromIntent = this.getIntent();
		String userid = this.getIntent().getStringExtra("userid");
		if (userid != null) {
			intent.putExtra("userid", userid);
		}
		if (height != 0) {
			intent.putExtra("height", height);
			startActivity(intent);
		} else {
			Toast.makeText(this, "身高不能为0！！", Toast.LENGTH_SHORT).show();
		}
	}

	@Override
	protected void onResume() {
		super.onResume();

	}

	@Override
	protected void onPause() {
		super.onPause();

	}

	@Override
	public void preInit() {

	}

	@Override
	public void initView() {
		// title
		TitleBar titleBar = (TitleBar) findViewById(R.id.title_bar);
		titleBar.onClickBack(this);
		TextView tvTitle = titleBar.getTitle();
		tvTitle.setText(getString(R.string.tv_start_height));

		// 右侧标尺
		heightShow = (TextView) findViewById(R.id.tv_start_height_show);
		heightView = (HeightView) findViewById(R.id.hv_start_height);
	}

	@Override
	public void loadData() {
		heightView.setHandler(mHandler);
	}

	@Override
	public void onBackPressed() {
		this.finish();
		super.onBackPressed();
	}

}
